Coloris.js 커스터마이징
작성일 : 2025.03.19
부모 요소 설정 문제
Coloris.js 색상 선택기 라이브러리의 parent 옵션 문제
// The default behavior is to append the color picker's dialog to the end of the document's
// body. but it is possible to append it to a custom parent instead. This is especially useful
// when the color fields are in a scrollable container and you want the color picker's dialog
// to remain anchored to them. You will need to set the CSS position of the desired container
// to "relative" or "absolute".
// The value of this option can be either a CSS selector or an HTMLElement/Element/Node.
// Note: This should be a scrollable container with enough space to display the picker.
parent: '.container',
이 코드에 대한 설명:
- 색상 선택기는 기본적으로 문서의 body 끝에 추가됨
- 사용자 지정 부모 요소에 추가 가능
- 이는 스크롤 가능한 컨테이너 내 색상 필드가 있고 선택기를 그에 고정시키고 싶을 때 유용
- 원하는 컨테이너의 CSS position 속성을 "relative" 또는 "absolute"로 설정해야 함
- 이 옵션에는 CSS 선택자나 HTMLElement/Element/Node를 사용할 수 있음
대시보드 UI에서의 문제
사용자는 .ib-sidebar-content를 부모로 설정했을 때 대시보드 화면에서 색상 선택기가 이상하게 표시되는 문제를 겪고 있었습니다:
Coloris({
el: '.coloris, [data-coloris]',
themeMode: 'light',
alpha: true,
format: 'hex',
focusInput: true,
formatToggle: false,
clearLabel: 'Clear',
selectInput: true,
inline: false,
closeButton: true,
clearButton: true,
parent: '.ib-sidebar-content', // 문제가 되는 부분
wrap: true,
margin: 2,
swatches: [
'#264653',
'#2a9d8f',
'#e9c46a',
'#f4a261',
'#e76f51'
]
});
제안된 해결책:
-
부모 설정 변경:
parent: 'body' // 또는 이 옵션 제거 -
부모 요소의 CSS 설정 추가:
.ib-sidebar-content { position: absolute; /* 또는 relative */ } -
스크롤 이벤트 처리:
document.addEventListener('scroll', function() { Coloris.close(); }, true);
입력 필드 숨기기와 썸네일만 표시하기
사용자가 입력 필드를 숨기고 색상 썸네일만 표시하고 싶다는 요청
<div class="color-pickers ${(item?.value)?"":"hidden"}" >
<input type="text" name="${item.name}" value="${(item?.value)?item.value:"#000000"}" class="coloris" data-coloris disabled>
</div>
제안된 CSS 해결책:
/* input 필드 숨기기 */
.coloris {
width: 0;
height: 0;
padding: 0;
border: 0;
position: absolute;
visibility: hidden; /* 이 방법은 문제될 수 있음 */
}
/* 대신 색상 표시 박스만 보이게 하기 */
.clr-field {
display: inline-block;
}
.clr-field button {
display: block;
width: 30px;
height: 30px;
border-radius: 4px;
cursor: pointer;
}
중요 참고사항: visibility: hidden을 사용하면 Coloris가 제대로 작동하지 않을 수 있습니다.
다른 방법:
.clr-field input[type="text"] {
width: 0;
height: 0;
padding: 0;
border: 0;
margin: 0;
opacity: 0;
position: absolute;
pointer-events: none;
}
다양한 썸네일 스타일
사용자는 다양한 썸네일 스타일에 대한 정보를 요청했습니다: